import namespace from "../namespace";
import Snap from "snapsvg";

namespace.io.Writer = {
  toJSON(canvas) {
    let result = [];
    canvas.getFigures().each((i, f) => {
      result.push(f.getPersistentAttrs());
    });
    return result;
  },

  getSvgWithoutSeat(canvas) {
    let svg = Snap.parse(canvas.paper.toString());
    svg.selectAll(".seat").forEach(e => e.remove());
    return svg.node.outerHTML;
  },

  getSeats(canvas) {
    let result = [];
    canvas.getFigures().each((i, f) => {
      if (f instanceof namespace.shape.SeatCircle) {
        result.push(f.getPersistentAttrs());
      }
    });
    return result;
  }
};
